<template>
    <div class="app-container">
        <div style="text-align: center;margin-bottom: 30px">
            火情预警更新
        </div>
        <el-form :model="infoForm" ref="infoForm" label-width="150px">
            <el-row :gutter="10">
                <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                    <el-form-item label="预警名称" prop="name" >
                        <el-input type="text" v-model="infoForm.name"  clearable disabled style="width: 100%"></el-input>
                    </el-form-item>
                </el-col>
<!--                <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">-->
<!--                    <el-form-item label="预警编码" prop="code">-->
<!--                        <el-input v-model="infoForm.code" placeholder="请输入预警编码" clearable></el-input>-->
<!--                    </el-form-item>-->
<!--                </el-col>-->
                <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                    <el-form-item label="所属主体" prop="enterpriseId" v-if="enterPriseHidden">
                        <el-select v-model="infoForm.enterpriseId" placeholder="请选择主体" style="width: 100%"  clearable @clear="clearInput2()">
                            <el-option v-for="(item,index) in enterpriseDominantList" :key="index"  :value="item.ucId" :label="item.name"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                    <el-form-item label="设备" prop="equipmentId" >
                        <el-select v-model="infoForm.equipmentId" placeholder="请选择设备"
                                   style="width: 100%">
                            <el-option v-for="(item,index) in equipmentList" :key="index"  :value="item.ucId" :label="item.disPlayName"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                    <el-form-item label="预警时间" prop="alarmTime" >
                        <el-date-picker
                                v-model="infoForm.alarmTime"
                                type="datetime"
                                placeholder="选择日期时间"
                                style="width: 100%">
                        </el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                    <el-form-item label="预警内容" prop="alarmInfo" >
                        <el-input v-model="infoForm.alarmInfo" placeholder="请输入预警内容" clearable style="width: 100%" ></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8" >
                    <el-form-item label="企业控制室确认时间" prop="enterpriseConfirmTime" >
                        <el-date-picker
                                v-model="infoForm.enterpriseConfirmTime"
                                type="datetime"
                                placeholder="选择日期时间"
                                style="width: 100%">
                        </el-date-picker >
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                    <el-form-item label="巡检人员确认时间" prop="userConfirmTime" >
                        <el-date-picker
                                v-model="infoForm.userConfirmTime"
                                type="datetime"
                                placeholder="选择日期时间"
                                style="width: 100%">
                        </el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                    <el-form-item label="消防确认时间" prop="manageConfirmTime" >
                        <el-date-picker
                                v-model="infoForm.manageConfirmTime"
                                type="datetime"
                                placeholder="选择日期时间"
                                style="width: 100%">
                        </el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                    <el-form-item label="巡检人员到达时间" prop="userArriveTime" >
                        <el-date-picker
                                v-model="infoForm.userArriveTime"
                                type="datetime"
                                placeholder="选择日期时间"
                                style="width: 100%">
                        </el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                <el-form-item label="反馈类型" prop="feedtype" >
                    <el-select v-model="infoForm.feedtype" placeholder="请选择反馈类型"
                               style="width: 100%">
                        <el-option :value="0" label="误报"></el-option>
                        <el-option :value="1" label="故障"></el-option>
                        <el-option :value="2" label="火情"></el-option>
                    </el-select>
                </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                    <el-form-item label="反馈内容" prop="feedback" >
                        <el-input v-model="infoForm.feedback" placeholder="请输入反馈内容" clearable style="width: 100%"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                    <el-form-item label="详细地址" prop="location" >
                        <el-input v-model="infoForm.location" placeholder="请输入详细地址" clearable style="width: 100%"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                    <el-form-item label="处理意见" prop="disposalOpinions" >
                        <el-input v-model="infoForm.disposalOpinions" placeholder="请输入处理意见" clearable style="width: 100%"></el-input>
                    </el-form-item>
                </el-col>

            </el-row>
        </el-form>
        <div slot="footer" style="text-align: center" class="dialog-footer">
            <el-button @click="cancelInfo">取 消</el-button>
            <el-button   type="primary" @click="updateInfo">修 改</el-button>
        </div>
    </div>

    </template>
<script>
import {getInFireAlarmInfoVo,updateInFireAlarmInfo} from "@/api/fireAlarmInfo";
import {getInEnterpriseList} from "@/api/enterprise";
import {getEquipmentList} from "@/api/equipment";
import {getInEnterpriseDominantList} from "@/api/enterpriseDominant";


export default {
    name: "infoEdit",
    data() {
        return {
            infoForm: {

            },
            enterpriseDominantList:[],
            equipmentList:[],

        }
    },

    computed: {
        createStatus() {
            return this.$route.params.ucId == '0'
        },
      enterPriseHidden(){
        let roleCode = this.$store.getters.roleCode;
        return roleCode=="ADMIN"||roleCode=="XT-ADMIN"||roleCode=="ZD-ADMIN"||roleCode=="DD-ADMIN"||roleCode=="JW-ADMIN"
      },
    },
    created() {
        this.getInEnterpriseDominantList()
              this.getEquipmentList()
            let ucId = this.$route.params.ucId
            this.getInFireAlarmInfoVo(ucId)

    },
    methods: {
        getInFireAlarmInfoVo(val) {
            getInFireAlarmInfoVo({ucId: val}).then(res => {
                this.infoForm = res.data
            }).catch(res => {

            })
        },
        cancelInfo() {
          window.history.back()
        },
        updateInfo() {

            this.$refs['infoForm'].validate(valid => {
                if (valid) {
                    updateInFireAlarmInfo(this.infoForm).then(res => {
                        this.$notify.success({
                            title: '成功',
                            message: "更新预警信息成功"
                        })
                        this.cancelInfo()
                    }).catch(res => {

                        this.$notify.error({
                            title: '失败',
                            message: res.msg
                        })
                    })
                } else {

                    console.log("表单验证不通过")
                }
            })
        },
        getInEnterpriseDominantList(){
            getInEnterpriseDominantList({deleted:false}).then(res=>{
                this.enterpriseDominantList = res.data
            }).catch(error=>{

            })
        },
        getEquipmentList(){
            getEquipmentList({deleted:false}).then(res=>{
                console.log(res.data)
                this.equipmentList = res.data
            }).catch(error=>{

            })
        },

    }

}
</script>
